macro 'Draw Histogram';
var
  max,scale:real;
  i,margin,width,height:integer;
begin
  SaveState;
  Margin:=10;
  width:=256;
  height:=0.6*256;
  Measure;
  SetForegroundColor(255);
  SetBackgroundColor(0);
  SetLineWidth(1);
  SetNewSize(width+2*margin,height+2*margin);
  MakeNewWindow('Histogram');
  MakeRoi(margin,margin-1,width,height+1);
  DrawBoundary;
  max:=0;
  for i:=1 to 254 do
  if histogram[i]> max then max:=histogram[i];
  scale:=height/max;
  for i:=1 to 254 do begin
    MakeRoi(margin+i,margin,1,histogram[i]*scale);
    SetForegroundColor(i);
    fill;
 end;
  SelectAll;
  FlipVertical;
  KillRoi;
  RestoreState;
end;

